package net.awpspace.mobile.management.note;

import java.util.Vector;

import javax.microedition.midlet.MIDlet;

import net.awpspace.mobile.form.BaseForm;

import com.sun.lwuit.List;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;

public class ViewNotes extends BaseForm {
	private static ViewNotes self;
	private AudioManager audio = AudioManager.getInstance();

	public ViewNotes(MIDlet app, BaseForm parent) {
		super(app, parent);
		// TODO Auto-generated constructor stub
		self = this;
		setTitle("Danh sách ghi chú");
		setTransitionOutAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_HORIZONTAL, true, 1200));
		init();
	}

	private List list;
	private Vector vector;

	private void init() {
		list = new List();
		list.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				audio.playSample("/button.mp3");
				int index = list.getSelectedIndex();
				Note note = (Note) vector.elementAt(index);
				new ViewDetailNote(app, self, note, index).show();
			}
		});
		vector = Dao.readDB();

		for (int i = 0; i < vector.size(); i++) {
			Note note = (Note) vector.elementAt(i);
			list.addItem(note.getName());
		}

		this.addComponent(list);
	}

	protected void processCommand(ActionEvent e) {
		// TODO Auto-generated method stub

	}

}
